package com.teamwings;

import com.teamwings.common.aspect.annotation.FormControlScan;
import com.teamwings.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.file.api.feign.FileServiceFeign;
import org.jeecg.common.form.api.IFormBaseExtAPI;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.api.ISysDepartServiceFeign;
import org.jeecg.common.system.api.ISysUserServiceFeign;
import org.jeecg.common.workflow.api.IWorkFlowBaseExtAPI;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication(scanBasePackages = {"org.jeecg.boot.starter.rabbitmq", "com.teamwings"})
@Slf4j
@FormControlScan(basePackage = {
        "com.teamwings.ctrls.formCtrls",
        "com.teamwings.ctrls.formCtrls.layout",
        "com.teamwings.ctrls.formCtrls.noField"
})
//使用Feign, 这里可以改为扫描路径
@EnableFeignClients(clients = {
        ISysBaseAPI.class,
        IFormBaseExtAPI.class,
        ISysUserServiceFeign.class,
        ISysDepartServiceFeign.class,
        FileServiceFeign.class,
        IWorkFlowBaseExtAPI.class
})
public class FormengineApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(FormengineApplication.class, args);
        SpringContextUtil.setApplicationContext(application);

        ConfigurableEnvironment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = "null".equals(String.valueOf(env.getProperty("server.servlet.context-path")))
                ? ""
                : String.valueOf(env.getProperty("server.servlet.context-path"));
        log.info("\n----------------------------------------------------------\n\t" +
                "自定义表单后台已启动! URLs:\n\t" +
                "本地: \t\t\thttp://localhost:" + port + path + "/\n\t" +
                "ip: \t\t\thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
    }
}
